# Variable
APP_NAME="http-server-template"
BUILD_DIR="build"

VERSION=$(shell git describe --abbrev=0 --tags)
COMMIT_ID=$(shell git rev-parse HEAD)
BUILD_DATE=$(shell date +'%F_%T_%Z')

LDFLAGS += -X template/server/http/cmd._Version_=${VERSION}
LDFLAGS += -X template/server/http/cmd._GitCommit_=${COMMIT_ID}
LDFLAGS += -X template/server/http/cmd._BuildDate_=${BUILD_DATE}
LDFLAGS += -s -w

# Function
.PHONY: help build clean
default:  help
help:
	@echo "usage: make <option>"
	@echo "options and effects:"
	@echo "    help   : Show help"
	@echo "    build  : Build the binary of this project for current platform"
	@echo "    clean  : Clean build directory"
build: clean
	@echo "build is running"
	@CGO_ENABLED=0 go build -o ${BUILD_DIR}/${APP_NAME}__${VERSION} -ldflags '$(LDFLAGS)'
	@echo "build was completed"
clean:
	@echo "clean is running"
	@rm -rf build/*
	@echo "clean was completed"